package zhtt03.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhtt03.service.User03Service;

/**
 * Created by zhtt on 2016/10/31.
 */
@RestController
@RequestMapping("user3")
public class User03Controller {

    @Autowired    private User03Service service;

    @RequestMapping("/{id}")
    private Object get(@PathVariable("id") Long id) {
        try{
            return service.findById(id);
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @RequestMapping("/{name}/{email}")
    private Object save(@PathVariable("name") String name,@PathVariable("email") String email) {
        try{
            service.save(name,email);
            return "保存成功！";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @RequestMapping("/{id}/{name}/{email}")
    private Object update(@PathVariable("id") int id,@PathVariable("name") String name,@PathVariable("email") String email) {
        try{
            service.update(id, name, email);
            return "保存成功！";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }
}
